#!/bin/sh

############################################

#############以下步骤可以自动执行##############

############################################

# 修复locale错误

locale="export LC_ALL=C"
$locale
sudo apt-get update
# 安装uwsgi
sudo apt-get -y --force-yes install uwsgi
# 安装mysql
sudo apt-get -y --force-yes install mysql-server
sudo apt-get -y --force-yes install python-mysqldb
sudo apt-get -y --force-yes install libmysqlclient-dev
ufw="sudo ufw allow 3306"
$ufw
# 安装git
sudo apt-get -y --force-yes install git
# 安装pip
sudo apt-get -y --force-yes install python-pip
# 升级pip
sudo pip install --upgrade pip
# 安装screen
sudo apt-get -y --force-yes install screen
# 安装openssl（可选）
# wget http://www.openssl.org/source/openssl-1.0.2a.tar.gz
# sudo tar -zxvf openssl-1.0.2a.tar.gz -C /usr/local/src/
# cd /usr/local/src/openssl-1.0.2a/
# sudo ./config
# sudo make && sudo make install
# apt安装nginx
sudo apt-get -y --force-yes install nginx
# 安装virtualenv
sudo apt-get install -y --force-yes virtualenv
# 创建虚拟环境
# virtualenv --no-site-packages django
# source="source django/bin/activate"
# $source
# 克隆项目（请修改为你自己的码云账号）
git clone https://570981884%40qq.com:Ringlove962464@gitee.com/1109599636/backend.git
# 配置nginx
cd backend/ && sudo cp ~/backend/nginx_xiaogongren.conf /etc/nginx/site-enabled && sudo rm -f /etc/nginx/site-enabled/default
# 安装程序依赖
sudo pip install -r requirements.txt -i https://pypi.douban.com/simple/
echo "Django Done!"

############################################

######确认以上步骤执行无误后再进行以下操作########

#############以下步骤需要手动执行##############

############################################

# nginx配置文件存放目录

# include /usr/local/nginx/conf.d/*.conf;

# include /usr/local/nginx/sites-enabled/*;

############################################

# 切换到一个新的screen使用uwsgi部署

# sudo uwsgi --ini uwsgi.ini

############################################

# Ubuntu配置mysql访问被拒绝的解决办法

# http://blog.csdn.net/SCTU_vroy/article/details/53019198

# sudo ufw allow 3306

# sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf （注释掉127.0.0.1哪一行）

# GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'AaBb123456' WITH GRANT OPTION;

# FLUSH PRIVILEGES;

# service mysql restart

############################################